package com.ease.job.quartz.job;

import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.StatefulJob;
import org.springframework.context.ApplicationContext;

public abstract class AbstractStatefulCronJob extends AbstractCronJob implements StatefulJob {

	/**
	 *
	 */
	private static final long serialVersionUID = 3911063932937162304L;

	private ApplicationContext applicationContext;

	// private long userId;// get UserContext for auditLog
	//
	// private UserContext userContext;

	protected Object getBean(String beanName) {
		return this.getApplicationContext().getBean(beanName);
	}

	// protected void init(JobExecutionContext context) {
	// try {
	// applicationContext = (ApplicationContext) context.getScheduler().getContext().get(APPLICATION_CONTEXT_KEY);
	//
	// UserSessionManagementService userSessionManagementService = (UserSessionManagementService)
	// getBean("userSessionManagementService");
	// UserSessionContext userSessionContext = userSessionManagementService.loadUserSession(userId, new Endpoint("TBD"),
	// new Endpoint("TBD"));
	// if (null != userSessionContext) {
	// userContext = userSessionContext.getUserContext();
	// }
	// } catch (Exception e) {
	// throw new RuntimeException(e);
	// }
	// }

	protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
		// init(context);
		// Assertion.notNull(userContext, "userContext not found, userId=" + userId);
		// doExecute(context);
	}

	// protected abstract void doExecute(JobExecutionContext context) throws JobExecutionException;

	// /**
	// * @return the userContext
	// */
	// public UserContext getUserContext() {
	// return userContext;
	// }
	//
	// /**
	// * @param userContext
	// * the userContext to set
	// */
	// public void setUserContext(UserContext userContext) {
	// this.userContext = userContext;
	// }

	/**
	 * @return the applicationContext
	 */
	public ApplicationContext getApplicationContext() {
		return applicationContext;
	}

	/**
	 * @param applicationContext
	 *            the applicationContext to set
	 */
	public void setApplicationContext(ApplicationContext applicationContext) {
		this.applicationContext = applicationContext;
	}

	// /**
	// * @return the userId
	// */
	// public long getUserId() {
	// return userId;
	// }
	//
	// /**
	// * @param userId
	// * the userId to set
	// */
	// public void setUserId(long userId) {
	// this.userId = userId;
	// }
}
